package com.itheima.tliasproject;

import com.itheima.tliasproject.interceptor.LoginCheckInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    private final LoginCheckInterceptor loginCheckInterceptor;

    // 依赖注入拦截器
    public WebMvcConfig(LoginCheckInterceptor loginCheckInterceptor) {
        this.loginCheckInterceptor = loginCheckInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginCheckInterceptor)
                .addPathPatterns("/**") // 拦截所有请求
                .excludePathPatterns(   // 放行不需要登录的路径
                    "/login",          // 登录接口（必须放行，否则无法登录）
                    "/static/**",      // 静态资源（如前端页面、图片）
                    "/swagger-ui/**",  // 若使用Swagger，需放行文档路径
                    "/v3/api-docs/**"
                );
    }
}